package test;
import static org.junit.Assert.*;

import java.io.IOException; 
import java.net.SocketException; 
import java.util.ArrayList;

import org.junit.Test;

import plugin.BroadcastAlgorithm;


import Phase1.*; 
import Phase2.Node;
/**
 * 
 * Black box testing for BroadcastAlgorithm
 * @author djb0646
 *
 */
public class testBlackBoxBroadAlg 
{
	
	
	// test perfect coverage
	@Test
	public void testIsAllNodeCoverd() throws InterruptedException
	{
	
		final int SIZE = 20;
		Node[] nodes = new Node[SIZE];
		nodes[0] = new Node();
		for(int i = 1; i < SIZE; i++)
		{
			nodes[i] = new Node();
			nodes[0].insert(nodes[i]);
		}
	 	ArrayList results = new ArrayList<Node>();
	 	results.add(nodes[0]);
		BroadcastAlgorithm ba = new BroadcastAlgorithm();
		for(int i = 0; i < SIZE; i++)
		{
			results.addAll((ArrayList<Node>) nodes[i].acceptWithResponse(ba, 0)); 
		}
		assertEquals(SIZE, results.size());
		 
	}
	// one node web
	@SuppressWarnings("unchecked")
	@Test
	public void testOneNode() throws InterruptedException
	{
	 
		BroadcastAlgorithm ba = new BroadcastAlgorithm();
		Node test = new Node();
		assertEquals(0, ((ArrayList) test.acceptWithResponse(ba, 1)).size());
		 
	}
	// two node web
	@SuppressWarnings("unchecked")
	@Test
	public void testTwoNode() throws InterruptedException
	{
	 
		BroadcastAlgorithm ba = new BroadcastAlgorithm();
		Node test = new Node();
		Node test1 = new Node();
		test.insert(test1);
		assertEquals(1, ((ArrayList) test.acceptWithResponse(ba, 0)).size());

		assertEquals(0, ((ArrayList) test1.acceptWithResponse(ba, 0)).size());
		 
	}

	 
}
